﻿
/****** Object:  User Defined Function dbo.IntreDatele    Script Date: 22/02/2006 5:44:11 PM ******/
CREATE FUNCTION IntreDatele (@Valoare DECIMAL(20,2), @dataStart datetime, @dataEnd datetime,@dataVerificata datetime)  
RETURNS DECIMAL(20,2) AS  
BEGIN 
	DECLARE @ret DECIMAL(20,2)
	SET @ret = 0
	if (@dataStart is NULL) AND (@dataEnd IS NULL)
		 SET @ret = @Valoare
	ELSE
	BEGIN
		if @dataStart is NULL
			BEGIN
				IF (@dataVerificata <=@dataEnd) 
					SET @ret = @Valoare
			END
		ELSE
		BEGIN	
			if @dataEnd is NULL 
				BEGIN
					IF  @dataVerificata >=@dataStart
						SET @ret = @Valoare
				END
			ELSE
				BEGIN
					if (@dataVerificata >= @dataStart) AND (@dataVerificata<=@dataEnd)
						SET @ret = @Valoare
				END
		END
	END
	RETURN @ret	
END